package edu.cuit.avatar.loop;

import java.util.Scanner;

/**
 * 使用穷举法计算最大公约数
 */
public class GreatestCommonDivisor {
    public static void main(String[] args) {
        System.out.println("请输入两个整数:");
        Scanner input = new Scanner(System.in);
        int number1 = input.nextInt(),
            number2 = input.nextInt();

        input.close();
        //最大公约数
        int gcd = 1;

        for (int k = 2; k <= number1 && k <= number2; k++){
            if(number1 % k == 0 && number2 % k == 0)
                gcd = k;
        }

        System.out.printf("(%d, %d)的最大公约数:%d", number1, number2, gcd);
    }
}
